<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 3000px;
            background-color: antiquewhite;
        }

        span {
            position: fixed;
            right: 100px;
            bottom: 150px;
            display: inline-block;
            width: 50px;
            text-align: center;
            line-height: 50px;
            background: rgb(226, 218, 218);
            display: none;
        }
    </style>
</head>

<body>
    <span>↑</span>
    <script>
        let span = document.querySelector('span')
        window.addEventListener('scroll', function () {
            // console.log(document.documentElement.scrollTop);
            if (document.documentElement.scrollTop >= 500) {
                span.style.display = 'block'
            } else {
                span.style.display = 'none'
            }
        })
        span.addEventListener('click', function () {
            document.documentElement.scrollTop = 0
        })
    </script>
</body>

</html>